package com.jiantong.user.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.user.impl.dao.BreedFactoryDao;
import com.jiantong.user.model.BreedFactory;
import com.jiantong.user.service.BreedFactoryWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 养殖档案-养殖地图
 * Created by mz03 on 2017/3/22.
 * zyp
 */
@Slf4j
@Service
@RpcProvider
public class BreedFactoryWriteServiceImpl implements BreedFactoryWriteService{

    private final BreedFactoryDao breedFactoryDao;
    @Autowired
    public BreedFactoryWriteServiceImpl(BreedFactoryDao breedFactoryDao){
        this.breedFactoryDao = breedFactoryDao;
    }



    /**
     * 产地检疫 创建新单据
     *
     * @param breedFactory 单据对象
     * @return 主键id
     */
    @Override
    public Response<Long> create(BreedFactory breedFactory) {
        try {
            breedFactoryDao.create(breedFactory);
            return Response.ok(breedFactory.getId());
        }catch (Exception e) {
            log.error("failed.to.create.breedFactory:{}", Throwables.getStackTraceAsString(e));
            return Response.fail("create.failed");
        }
    }

    /**
     * 产地检疫 更新单据
     *
     * @param breedFactory 单据对象
     * @return true or false
     */
    @Override
    public Response<Boolean> update(BreedFactory breedFactory) {
        try{
            return Response.ok(breedFactoryDao.update(breedFactory));
        }catch (Exception e){
            log.error("failed to update breed factory error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("update.failed");
        }
    }
}
